Skip to content

Stop deploy/opensearch/operator.py shadowing the stdlib operator module - #601

Merged
suguanYang merged 1 commit into
mainfrom
fix/wangbinqi/opensearch-operator-shadowing
Dec 1, 2026
Merged

suguanYang merged 1 commit into
mainfrom
fix/wangbinqi/opensearch-operator-shadowing

Conversation

@suguanYang

Copy link
Copy Markdown
Contributor

Summary

Scripts in deploy/opensearch run with that folder first on sys.path. Python's own collections module imports operator at startup, which resolved to our deploy/opensearch/operator.py:

python deploy/opensearch/manage.py
  collections/__init__.py: from operator import eq
    → deploy/opensearch/operator.py      # ours, not the stdlib
      → ImportError: cannot import name 'eq' from partially initialized module 'operator'

It stays hidden in the usual workspace environment only because the shared package's editable-install .pth imports collections before the script folder is added to the path. Any environment without that .pth crashes: a bare virtualenv, python -S, or a non-editable install.

 deploy/opensearch/
-├── operator.py
+├── native_operator.py        # same content; name workload_snapshot.py already loads it as
 ├── launch-issuer.py          # "operator" kind → native_operator.py
 ├── workload_snapshot.py      # path updated
 ├── manage.py                 # error message updated
 ├── tests/test_execution.py   # paths updated
 └── README.md                 # command examples updated

The launch-issuer.py --kind operator name is unchanged, so generated backup services keep the same command line. The transition_script_sha256 checks hash scripts/probes/manage-opensearch-transition.py, which this PR does not touch.

Evidence

  • Before (main, Python 3.12, same packages, no .pth processing):
    manage.py --help   → ImportError: cannot import name 'eq' from partially initialized module 'operator'
    operator.py --help → same ImportError
    
    After:
    manage.py --help          → usage: manage.py [-h] ...
    native_operator.py --help → usage: native_operator.py [-h] --manifest MANIFEST --plan PLAN ...
    
  • Full deploy/opensearch/tests suite on Python 3.12 in the workspace environment: 135 passed on both main and this branch. The one remaining failure, test_offline_admission, needs application settings (DATABASE_URL, TMP_PATH) and fails the same way on main.
  • Ruff passes on the changed files.

Merge Danger

Door: two-way

A file rename with reference updates. Reverting restores the old name.

Blast Radius: operator-commands

Operators who run the script by name now type native_operator.py fence-host and similar. The README is updated. Hosts using an older reviewed checkout keep the old file name until their checkout is updated. Commands that go through launch-issuer.py --kind operator resolve the new path once the checkout includes this change.

🤖 Generated with Claude Code

Scripts in deploy/opensearch run with that folder first on sys.path, so
Python's own `import operator` (from collections, at startup) loaded the
repository's operator.py and failed with a circular-import ImportError.
It stayed hidden only because the shared package's editable-install .pth
happens to import collections before the script folder is added.

Rename the module to native_operator.py, the name workload_snapshot.py
already loads it under, and update every reference. The launch-issuer
kind stays `operator`, so installed backup services keep their command.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@suguanYang
suguanYang merged commit 911faff into main Dec 1, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant